<template>
  <div class="app-container">
    <div style="font-size: 25px;">查看入库信息</div>
    <!--横线组件纯纯为了页面好看-->
    <el-divider></el-divider>
    <el-form ref="form" :model="form" :rules="rules" label-width="150px">
      <el-row>
        <el-col :span="8">
          <el-form-item label="采购单号" prop="poNo">
            <el-input v-model="pono" placeholder="请输入采购单号" style="width: 230px;" oninput="value=value.replace(/[^\d\w]/g,'')" maxlength="25" disabled/>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="供应商" prop="supplierId">
            <el-select v-model="form.supplierId" placeholder="请选择供应商" style="width: 230px;" disabled>
              <el-option
                v-for="dict in supplierlist"
                :key="dict.id"
                :label="dict.supplierName"
                :value="dict.id"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="付款方式" prop="paymentType">
            <el-select v-model="form.paymentType" placeholder="请选择付款方式" style="width: 230px;" disabled>
              <el-option
                v-for="dict in dict.type.erp_payment_type"
                :key="dict.value"
                :label="dict.label"
                :value="parseInt(dict.value)"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="供应商联系人" prop="supplieruser">
            <el-input v-model="supplieruser" placeholder="请输入供应商联系人" style="width: 230px;" maxlength="25" disabled/>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="供应商手机号" prop="supplierphone">
            <el-input v-model="supplierphone"
                      placeholder="请输入供应商手机号"
                      style="width: 230px;"
                      maxlength="15"
                      @input="v => supplierphone = v.replace(/[^\d]/g,'')" disabled/>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="类型" prop="processType" >
            <el-select v-model="form.processType" placeholder="请选择类型" disabled>
              <el-option
                v-for="dict in dict.type.erp_purchase_type"
                :key="dict.value"
                :label="dict.label"
                :value="parseInt(dict.value)"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="退货状态" prop="returnGoods">
            <el-select v-model="form.returnGoods" placeholder="请选择退货状态" disabled>
              <el-option
                v-for="dict in dict.type.erp_return_goods"
                :key="dict.value"
                :label="dict.label"
                :value="parseInt(dict.value)"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="入库单号" prop="shipmentNum">
            <el-input v-model="form.shipmentNum" placeholder="请输入入库单号" style="width: 230px;" oninput="value=value.replace(/[^\d\w]/g,'')" maxlength="25" disabled/>
          </el-form-item>
        </el-col>
      </el-row>


      <el-form-item label="备注" prop="remarks">
        <el-input v-model="form.remarks" type="textarea" placeholder="请输入备注"  style="width: 85%" maxlength="250" disabled/>
      </el-form-item>
    </el-form>
    <!--横线组件纯纯为了页面好看-->
    <el-divider></el-divider>
    <el-row style="margin-bottom: 20px;">
      <el-col :span="1.5">
        <div style="font-size: 20px; margin-top: 5px">采购商品</div>
      </el-col>
    </el-row>
    <el-table :data="addGoodsList" show-summary :summary-method="getSummaries" default-expand-all :row-class-name="getRowClassName">
      <!--      <el-table-column type="selection" width="80" align="center"/>-->
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-table v-show="props.row.erpGoodsPurchaseWarehouseList.length != 0" v-bind:data="props.row.erpGoodsPurchaseWarehouseList"
                    :default-expand-all="true" show-summary :summary-method="getSummaries" :show-header="true"
                    :header-cell-style="{background:'#FFFFFF',color:'#606266'}">
            <el-table-column prop="warehouseName" align="center" label="入库仓库"/>
            <el-table-column prop="purchaseGoodNumber" align="center" label="入库数量"/>
            <el-table-column prop="returnGoodNumber" align="center" label="退货数量"/>
            <el-table-column prop="returnGoodBonus" align="center" label="退货金额"/>
          </el-table>
        </template>
      </el-table-column>
      <el-table-column label="商品ID" align="center" prop="id"/>
      <el-table-column label="商品名称" align="center" prop="name"/>
      <el-table-column label="分类" align="center" prop="categoryName"/>
      <el-table-column label="品牌" align="center" prop="brandName"/>
      <el-table-column label="采购单价" align="center" prop="monovalent">
        <div class="item" slot-scope="scope">
          <el-input class="item__input" v-model="scope.row.monovalent" placeholder="请输入价格" size="mini" style="width:100px"
                    @input="handleEdit(scope.$index, scope.row)"
                    maxlength="10"
                    @keyup.native="scope.row.monovalent = scope.row.monovalent = scope.row.monovalent.replace(/[^\d.]/g,'');
                                   scope.row.monovalent = scope.row.monovalent.replace(/\.{2,}/g,'.');
                                   scope.row.monovalent = scope.row.monovalent.replace(/^\./g,'');
                                   scope.row.monovalent = scope.row.monovalent.replace('.','$#$').replace(/\./g,'').replace('$#$','.');
                                   scope.row.monovalent = scope.row.monovalent.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');"
                    disabled
          ></el-input>
        </div>
      </el-table-column>
      <el-table-column label="采购数量" align="center" prop="quantity">
        <div class="item" slot-scope="scope">
          <el-input-number disabled v-model="scope.row.quantity" oninput="value=value.replace(/[^0-9.]/g,'')" controls-position="right" :min="0" size="mini" style="width:100px"  @input="handleEdit(scope.$index, scope.row)"/>
        </div>
      </el-table-column>
      <el-table-column label="采购总价" align="center" prop="total">
        <div class="item" slot-scope="scope">
          <el-input  disabled class="item__input" v-model="scope.row.total" placeholder="销售总价" size="mini" style="width:100px" readonly="readonly"></el-input>
        </div>
      </el-table-column>
    </el-table>

    <div slot="footer" class="dialog-footer" style="text-align:center;margin-top: 20px;">
      <el-button
        type="primary"
        v-if="isWarehousing ===1"
        @click="ConfirmReceipt"
      >确认入库</el-button>
      <el-button
        type="primary"
        @click="cancel"
      >返回</el-button>
    </div>

    <!--修改销售商品入库仓库弹出框 -->
    <el-dialog :title="title" :visible.sync="updateOpen" width="1500px" append-to-body :close-on-click-modal="false">
      <el-table v-loading="loading" :data="updateWarehouseList" show-summary :summary-method="getSummariesSurplus">
        <el-table-column label="商品ID" align="center" prop="goodsId"/>
        <el-table-column label="商品名称" align="center" prop="goodsName"/>
        <el-table-column label="仓库名称" align="center" prop="name"/>
        <el-table-column label="商品入库数量" align="center" prop="warehousingQuantity">
          <div class="item" slot-scope="scope">
            <el-input-number v-model="scope.row.warehousingQuantity" controls-position="right" :min="0" size="mini" style="width:100px" disabled/>
          </div>
        </el-table-column>
        <el-table-column label="退货数量" align="center" prop="warehousingReturnQuantity">
          <div class="item" slot-scope="scope">
            <el-input-number v-model="scope.row.warehousingReturnQuantity" controls-position="right" :min="0" size="mini" style="width:100px"/>
          </div>
        </el-table-column>
      </el-table>
      <div style="margin-left: 83%;margin-top: 10px;">
        <span style="font-size: 15px;font-weight: 700">商品总数：</span>
        <span style="font-size: 15px;font-weight: 700">{{warehousingTotalQuantity+" 个"}}</span>
      </div>
      <div slot="footer" class="dialog-footer" style="text-align:center;margin-top: 20px;">
        <el-button type="primary" @click="updateDetermine">确 定</el-button>
        <el-button type="primary" @click="cancelDetermine">取 消</el-button>
      </div>

    </el-dialog>
  </div>
</template>

<script>
import {getPurchase, editFlag, purchaseReceipt, updatePurchase} from "@/api/erp/purchase";
import {listSupplier} from "@/api/erp/supplier";
import {listGoodsPurchase, updateErpGoodsWarehousing, updateGoods} from "@/api/erp/goods";
import {listPurchaseoodsInfo} from "@/api/erp/purchaseGoods";
import {listWarehouse} from "@/api/erp/warehouse";
import {addPurchaseWarehouse, getWarehouseBySaleId} from "@/api/erp/goodsWarehouse";
import {
  addGoodsPurchaseWarehouse,
  delGoodsPurchaseWarehouse,
  updateGoodsPurchaseWarehouse
} from "@/api/erp/goodsPurchaseWarehouse";
import {addInvoicePurchase, getInvoicePurchase, updateInvoicePurchase} from "@/api/erp/invoicePurchase";
import {addReturnPurchase} from "@/api/erp/returnPurchase";
import {addReceiptDoc} from "@/api/erp/receiptDoc";
import {addCopeWith} from "@/api/erp/copeWith";

export default {
  name: "info",
  dicts: ['erp_warehousing_type', 'erp_return_goods', 'erp_process_type', 'erp_payment_type', 'erp_purchase_type'],
  data() {
    return {
      //入库单号
      receiptDocOrder: null,
      //采购入库单的入库状态
      isWarehousing:null,
      //入库总条数
      warehousingTotalQuantity: 0,
      //点击详情带过来的id
      purchaseId:null,
      //点击详情带过来的审核状态标识
      processType:null,
      monovalent:null,
      //随机生成的订单编号
      pono:"",
      //供应商联系人
      supplieruser:"",
      //供应商手机号
      supplierphone:"",
      //供应商Id
      supplierId:"",
      //付款类型(0应付账款1现金付款2预付款)
      paymentType:"",
      //有无退货(0有1无)
      isReturn:"",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 采购订单表格数据
      purchaseList: [],
      //供应商数据
      supplierlist: [],
      //仓库数据
      warehouseList: [],
      //修改入库仓库数据
      updateWarehouseList: [],
      //入库仓库名称
      warehousingWarehousingList: [],
      // 商品信息表格数据
      goodsList: [],
      // 添加的商品信息表格数据
      addGoodsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //入库仓库弹框控制
      warehousingOpen: false,
      //修改入库仓库弹框控制
      updateOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        poNo: null,
        goodsIds: null,
        supplierId: null,
        supplieruser: null,
        supplierphone: null,
        paymentType: null,
        warehousingType: null,
        returnGoods: null,
        processType: null,
        createUser: null,
        gettime:"",
        //采购单价
        monovalents: "",
        //采购数量
        quantitys: "",
        //采购总价
        totalPrices: "",

      },
      // 选择商品查询参数
      queryParamsGoods: {
        pageNum: 1,
        pageSize: 10,
        goodsIds: null,
        name: null,
        brandId: null,
        categoryId: null,
        type: null,
        labels: null,
        barCode: null,
      },
      //仓库查询参数
      queryParamsWarehouse: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        warehouseAdministrators: null,
        administratorsPhone: null,
        warehousePhone: null,
        warehouseCategory: null,
        warehouseAddress: null,
        querySelectedOptions: null,
        remarks: null,
        createUser: null,
        position: null,
        goodsId: null,
        goodsName: null,
        warehousingQuantity: null,
      },
      //修改商品查询数据
      queryParamsPurchaseGoods:{
        purchaseId:null,
      },
      //供应商查询参数
      queryParamsSupplier: {
        pageNum: 1,
        pageSize: 10,
        supplierName: null,
        supplierContacts: null,
        supplierPhone: null,
        supplierCategory: null,
        supplierAddress: null,
        supplierBank: null,
        supplierBankAccount: null,
        supplierDutyParagraph: null,
        detailedAddress: null,
        remarks: null,
        creatTime: null,
        creatUser: null
      },
      // 采购商品仓库关联表查询参数
      queryParamsGoodsPurchaseWarehouse: {
        pageNum: 1,
        pageSize: 10,
        warehouseId: null,
        purchaseId: null,
        purchaseGoodId: null,
        purchaseGoodNumber: null,
        returnGoodNumber: null,
        returnGoodBonus: null,
      },
      //采购入库单查询参数
      queryParamsInvoicePurchase: {
        pageNum: 1,
        pageSize: 10,
        purchaseOrderNum: null,
        shipmentNum: null,
        purchaseId: null,
        supplierId: null,
        paymentType: null,
        createUser: null,
        isReturn: null
      },
      // 表单参数
      form: {},
      formGoodsPurchaseWarehouse: {},
      formPurchaseReceipt: {},
      formInvoicePurchase: {},
      formPurchase: {},
      formPurchaseInvoice: {},
      formPurchaseWarehouse: {},
      formReturnPurchase: {},
      formReceiptDoc: {},
      formCopeWith: {},
      formGoods: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    //将带过来id赋值，用于修改审核状态
    this.purchaseId = this.$route.query.id
    this.getList();
    //查询修改关联商品数据
    this.getPurchaseGoods();
    //查询添加商品表方法
    this.getGoodsList();
    //查询供应商列表方法
    this.getSupplierlist();
    //查询仓库
    this.getWarehouse();
    //查询采购入库订单信息
    this.getInvoicePurchase();
    // 获取当前日期的方法
    this.getCurrentTime();
  },
  methods: {
    // 获取当前日期的方法
    getCurrentTime() {
      //获取当前时间并打印
      var _this = this;
      let yy = new Date().getFullYear().toString();
      let mm = (new Date().getMonth()+1).toString();
      let dd = new Date().getDate().toString();
      let hh = new Date().getHours().toString();
      let mf = (new Date().getMinutes()<10 ? '0'+new Date().getMinutes() : new Date().getMinutes()).toString();
      let ss = (new Date().getSeconds()<10 ? '0'+new Date().getSeconds() : new Date().getSeconds()).toString();
      _this.receiptDocOrder = "Erd"+yy+mm+dd+hh+mf+ss+ Math.floor(Math.random() * 10000)
    },
    //展开行状态
    getRowClassName({row, rowIndex}) {
      if (row.erpGoodsPurchaseWarehouseList.length == 0) {
        return 'row-expand-cover';
      }
    },
    /*查询仓库*/
    getWarehouse(){
      listWarehouse(this.queryParamsWarehouse).then(response => {
        this.warehouseList = response.rows;
      });
    },
    //采购入库按钮操作
    ConfirmReceipt(){
      let that = this;
      this.$modal.confirm('是否确认商品入库？').then(function() {
        //定义一个仓库空数组
        const storehouse = [];
        //定义一个退货总金额数
        let returnNum = 0;
        //定义一个入库总金额数
        let WarehouseNum = 0;
        for (let i = 0; i < that.addGoodsList.length; i++) {
          //定义一个退货总数
          let num = 0;
          //定义一个入库总数
          let Erdnum = 0;
          for (let j = 0; j < that.addGoodsList[i].erpGoodsPurchaseWarehouseList.length; j++) {
            /*判断如果有入库商品则将仓库名称保留*/
            if(that.addGoodsList[i].erpGoodsPurchaseWarehouseList[j].purchaseGoodNumber > 0){
              //获取入库仓库
              storehouse.push(that.addGoodsList[i].erpGoodsPurchaseWarehouseList[j].warehouseName)
            }
            /*获取入库总数*/
            Erdnum += that.addGoodsList[i].erpGoodsPurchaseWarehouseList[j].purchaseGoodNumber
            /*获取退货总数*/
            num += that.addGoodsList[i].erpGoodsPurchaseWarehouseList[j].returnGoodNumber
            that.formPurchaseWarehouse.goodId = that.addGoodsList[i].erpGoodsPurchaseWarehouseList[j].purchaseGoodId
            that.formPurchaseWarehouse.warehouseId = that.addGoodsList[i].erpGoodsPurchaseWarehouseList[j].warehouseId
            that.formPurchaseWarehouse.warehouseName = that.addGoodsList[i].erpGoodsPurchaseWarehouseList[j].warehouseName
            that.formPurchaseWarehouse.goodsNumber = that.addGoodsList[i].erpGoodsPurchaseWarehouseList[j].warehousingQuantity
            addPurchaseWarehouse(that.formPurchaseWarehouse).then(response => {
            });
            if(that.addGoodsList[i].erpGoodsPurchaseWarehouseList[j].warehousingQuantity > 0 ){
              that.formGoods.id = that.addGoodsList[i].erpGoodsPurchaseWarehouseList[j].purchaseGoodId
              that.formGoods.inventory = that.addGoodsList[i].erpGoodsPurchaseWarehouseList[j].warehousingQuantity
              updateErpGoodsWarehousing(that.formGoods).then(response => {
              });
            }
          }
          /*获得退货总金额数*/
          returnNum += Number(num)*Number(that.addGoodsList[i].monovalent)
          /*获得入库总金额数*/
          WarehouseNum += Number(Erdnum)*Number(that.addGoodsList[i].monovalent)
        }
        //新增采购退货单数据
        if(returnNum > 0){
          that.formReturnPurchase.purchaseId = that.$route.query.id
          that.formReturnPurchase.purchaseOrderNum = that.form.poNo
          that.formReturnPurchase.shipmentNum = that.form.shipmentNum
          that.formReturnPurchase.returnBonus = returnNum
          that.formReturnPurchase.supplierId = that.form.supplierId
          that.formReturnPurchase.paymentType = that.form.paymentType
          that.formReturnPurchase.supplieruser = that.form.supplieruser
          that.formReturnPurchase.supplierphone = that.form.supplierphone
          that.formReturnPurchase.isReturn = 0
          addReturnPurchase(that.formReturnPurchase).then(response => {
          });
        }
        //定义一个空数组用来去重仓库名称
        let mapList = []
        //去重
        for(let i=0;i<storehouse.length;i++){
          if(mapList.indexOf(storehouse[i]) == '-1'){
            mapList.push(storehouse[i])
          }
        }
        /*将仓库数组转换成字符串*/
        let permission = mapList.join(",");
        //新增入库单数据
        that.formReceiptDoc.receiptDocOrder = that.receiptDocOrder
        that.formReceiptDoc.receiptDocAmount = WarehouseNum
        that.formReceiptDoc.receiptDocWarehouse = permission
        that.formReceiptDoc.purchaseId = that.$route.query.id
        that.formReceiptDoc.isSaleAllocation = 2
        addReceiptDoc(that.formReceiptDoc).then(response => {
        });
        /*新增财务应收账款*/
        that.formCopeWith.poNo = that.form.poNo
        that.formCopeWith.paymentType = that.form.paymentType
        that.formCopeWith.purchaseId = that.$route.query.id
        that.formCopeWith.amountPayable = WarehouseNum
        addCopeWith(that.formCopeWith).then(response => {
        });
        //修改入库状态
        that.formInvoicePurchase.id = that.$route.query.invoicePurchaseId
        that.formInvoicePurchase.isWarehousing = 0
        updateInvoicePurchase(that.formInvoicePurchase).then(response => {
        });
        // 修改采购订单类型
        that.formPurchase.id = that.$route.query.id
        that.formPurchase.processType = 3
        purchaseReceipt(that.formPurchase).then(response => {
        });
        that.$modal.msgSuccess("新增成功");
        that.cancel()
      })
    },


    //退货按钮的操作
    updateDetermine(){
      let that = this;
      this.$modal.confirm('是否确认退货？').then(function() {
        for (let i = 0; i < that.updateWarehouseList.length; i++) {
          if (that.updateWarehouseList[i].warehousingReturnQuantity === null || that.updateWarehouseList[i].warehousingReturnQuantity === "" || that.updateWarehouseList[i].warehousingReturnQuantity === undefined) {
            that.$modal.msgError("商品退货数量不能为空，且最小值为0！")
            return;
          }
          if (that.updateWarehouseList[i].warehousingReturnQuantity > that.updateWarehouseList[i].warehousingQuantity) {
            that.$modal.alertError("商品退货数量大于商品入库数量，请核实后修改！")
            return;
          }
          if (that.updateWarehouseList[i].warehousingReturnQuantity > 0 && that.updateWarehouseList[i].warehousingQuantity !== 0 && that.updateWarehouseList[i].warehousingQuantity >= that.updateWarehouseList[i].warehousingReturnQuantity) {
            that.formGoodsPurchaseWarehouse.id = that.updateWarehouseList[i].warehousingId
            that.formGoodsPurchaseWarehouse.returnGoodNumber = that.updateWarehouseList[i].warehousingReturnQuantity
            that.formGoodsPurchaseWarehouse.purchaseGoodNumber = that.updateWarehouseList[i].warehousingQuantity - that.updateWarehouseList[i].warehousingReturnQuantity
            updateGoodsPurchaseWarehouse(that.formGoodsPurchaseWarehouse).then(response => {
            });
          }
        }
        that.formPurchaseReceipt.id = that.$route.query.id
        that.formPurchaseReceipt.returnGoods = 0
        purchaseReceipt(that.formPurchaseReceipt).then(response => {
        });
        that.formInvoicePurchase.id = that.$route.query.invoicePurchaseId
        that.formInvoicePurchase.isReturn = 0
        updateInvoicePurchase(that.formInvoicePurchase).then(response => {
        });
        that.$modal.msgSuccess("退货成功");
        that.updateOpen = false;
        that.getPurchaseGoods();
        that.getList();
      });
    },

    //点击退货按钮查询数据操作
    returnWarehouse(row) {
      listWarehouse(this.queryParamsWarehouse).then(response => {
        this.warehouseList = response.rows;
      });
      for (let a = 0; a < row.erpGoodsPurchaseWarehouseList.length; a++) {
        for (let i = 0; i < this.warehouseList.length; i++) {
          this.warehouseList[i].goodsId = row.id
          this.warehouseList[i].goodsName = row.name
          if(this.warehouseList[i].id === row.erpGoodsPurchaseWarehouseList[a].warehouseId){
            this.warehouseList[i].warehousingId = row.erpGoodsPurchaseWarehouseList[a].id
            this.warehouseList[i].warehousingQuantity = row.erpGoodsPurchaseWarehouseList[a].warehousingQuantity
          }
        }
      }

      this.updateWarehouseList = this.warehouseList
      this.warehousingTotalQuantity = row.quantity
      this.updateOpen = true;
      this.title = "修改入库仓库";
    },
    //取消按钮操作
    cancelDetermine(){
      this.updateOpen = false;
      this.warehousingOpen = false;
    },
//商品小计
    getSummariesSurplus(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计';
          return;
        }
        const values = data.map(item => Number(item[column.property]));
        if (!values.every(value => isNaN(value))) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
          sums[index] +=' 个';
        } else {
          sums[index] = '';
        }
      });

      return sums;
    },
    /** 查询详情采购订单列表 */
    getList() {
      let purchaseId = this.$route.query.id
      //查询详情
      getPurchase(purchaseId).then(response => {
        this.form = response.data;
        //将审核状态赋值
        this.processType = response.data.processType
        this.pono = response.data.poNo
        this.supplieruser = response.data.supplieruser
        this.supplierphone = response.data.supplierphone
        this.supplierId = response.data.supplierId
        this.paymentType = response.data.paymentType
        this.isReturn = response.data.returnGoods
      });
    },
    /*查询详情关联商品数据*/
    getPurchaseGoods(){
      this.queryParamsPurchaseGoods.purchaseId = this.$route.query.id
      listPurchaseoodsInfo(this.queryParamsPurchaseGoods).then(response => {
        this.addGoodsList = response.rows
        for (let i = 0; i < this.addGoodsList.length ; i++) {
          for (let j = 0; j < this.addGoodsList[i].erpGoodsPurchaseWarehouseList.length; j++) {
            if(this.addGoodsList[i].erpGoodsPurchaseWarehouseList[j].returnGoodBonus ==null){
              this.addGoodsList[i].erpGoodsPurchaseWarehouseList[j].returnGoodBonus = 0;
            }
            if(this.addGoodsList[i].erpGoodsPurchaseWarehouseList[j].returnGoodNumber ==null){
              this.addGoodsList[i].erpGoodsPurchaseWarehouseList[j].returnGoodNumber = 0;
            }
          }
          this.addGoodsList[i].id = response.rows[i].goodsNumber
          this.addGoodsList[i].name = response.rows[i].goodsName
        }
      });
    },
    //查询供应商方法
    getSupplierlist(){
      listSupplier(this.queryParamsSupplier).then(response => {
        this.supplierlist = response.rows;
      });
    },
    //查询采购入库订单详情
    getInvoicePurchase(){
      const id = this.$route.query.invoicePurchaseId
      getInvoicePurchase(id).then(response => {
        this.isWarehousing = response.data.isWarehousing
      });
    },

    /** 查询商品列表 */
    getGoodsList() {
      this.loading = true;
      listGoodsPurchase(this.queryParamsGoods).then(response => {
        this.goodsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //商品小计
    getSummaries(param) {
      const {columns, data} = param;
      const sums = []; //声明变量
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "小计";
          return;
        }
        const values = data.map((item) => Number(item[column.property]));
        if (
          column.property === "total" ||
          column.property === "purchaseGoodNumber"||
          column.property === "returnGoodNumber"||
          column.property === "returnGoodBonus"
        ) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
        } else {
          sums[index] = '';
        }
      });
      return sums;
    },

    //商品总价计算
    handleEdit(index, row) {
      if(row.quantity && row.monovalent){
        row.total = Number(row.quantity)*Number(row.monovalent)

      }
    },
    // 取消按钮
    cancel() {
      this.$router.push({path: '/purchase/invoicePurchase'});
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        poNo: null,
        supplierId: null,
        paymentType: null,
        warehousingType: null,
        returnGoods: null,
        supplieruser: null,
        supplierphone: null,
        processType: null,
        createTime: null,
        updateTime: null,
        createUser: null
      };
      this.resetForm("form");
    },
    // 添加商品表单重置
    resetGoods() {
      this.formGoods = {
        id: null,
        name: null,
        thumbnail: null,
        banners: null,
        description: null,
        sortDescription: null,
        price: null,
        brandId: null,
        categoryId: null,
        cost: null,
        type: null,
        details: null,
        labels: null,
        inventory: null,
        sales: null,
        weight: null,
        supplierId: null,
        shelves: null,
        shopId: null,
        sort: null,
        createTy: null,
        updateTime: null,
        createTime: null,
        barCode: null,
        speclist: null,
        speclabellist: null
      };
      this.resetForm("formGoods");
    },
  }
};
</script>
<style>
.row-expand-cover .el-table__expand-icon {
  visibility: hidden;
}
</style>
